package com.jsz.peini.controller.app;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.ResourceBundle;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.jsz.peini.bean.app.SysConfig;
import com.jsz.peini.bean.codes.SystemCode;
import com.jsz.peini.bean.label.LabelUser;
import com.jsz.peini.bean.sign.SignInfo;
import com.jsz.peini.bean.task.PartyInfo;
import com.jsz.peini.bean.task.TaskInfo;
import com.jsz.peini.bean.task.TaskInfoExample;
import com.jsz.peini.bean.user.UserAccount;
import com.jsz.peini.bean.user.UserConcern;
import com.jsz.peini.bean.user.UserConcernExample;
import com.jsz.peini.bean.user.UserImageExample;
import com.jsz.peini.bean.user.UserInfo;
import com.jsz.peini.bean.user.UserInfoExample;
import com.jsz.peini.common.bean.ResultMessage;
import com.jsz.peini.common.constants.Constants;
import com.jsz.peini.common.util.AppPush;
import com.jsz.peini.common.util.DateTimeUtils;
import com.jsz.peini.common.util.EhcacheUtil;
import com.jsz.peini.common.util.FileUtils;
import com.jsz.peini.common.util.GetCode;
import com.jsz.peini.common.util.IdCardSend;
import com.jsz.peini.common.util.PeiniUtils;
import com.jsz.peini.common.util.ShieldTextFiltration;
import com.jsz.peini.common.util.SmsSendUtil;
import com.jsz.peini.mapper.app.SysConfigMapper;
import com.jsz.peini.mapper.comm.ImageFilterResultMapper;
import com.jsz.peini.mapper.task.TaskInfoMapper;
import com.jsz.peini.mapper.user.UserAccountMapper;
import com.jsz.peini.mapper.user.UserConcernMapper;
import com.jsz.peini.mapper.user.UserImageMapper;
import com.jsz.peini.mapper.user.UserInfoMapper;
import com.jsz.peini.mapper.user.UserSmsMapper;
import com.jsz.peini.redis.base.RedisConstants;
import com.jsz.peini.redis.base.RedisUtil;
import com.jsz.peini.redis.base.SerializeUtil;
import com.jsz.peini.redis.util.UserRedisUtil;
import com.jsz.peini.service.label.LabelInfoService;
import com.jsz.peini.service.sign.SignInfoService;
import com.jsz.peini.service.square.SquareInfoService;
import com.jsz.peini.service.task.TaskInfoService;
import com.jsz.peini.service.user.UserAccountService;
import com.jsz.peini.service.user.UserConcernService;
import com.jsz.peini.service.user.UserImageService;
import com.jsz.peini.service.user.UserInfoService;
import com.jsz.peini.vo.ImgVo;
import com.jsz.peini.vo.UserVo;

@Controller
public class UserInfoController {
	private static final Logger logger = LoggerFactory.getLogger(UserInfoController.class);
	@Autowired
	private UserInfoService userInfoService;
	
	@Autowired
	private SignInfoService signInfoService;
	
	@Autowired
	private UserAccountService userAccountService;
	
	@Autowired
	private LabelInfoService labelInfoService;
	
	@Autowired
	private UserImageService userImageService;
	
	@Autowired
	private TaskInfoService taskInfoService;
	
	@Autowired
	private SquareInfoService squareInfoService;
	
	@Autowired
	private UserConcernService userConcernService;
	@Resource
	private UserInfoMapper userInfoMapper;
	@Resource
	private UserConcernMapper userConcernMapper;
	@Resource
	private UserAccountMapper userAccountMapper;
	@Resource
	private TaskInfoMapper taskInfoMapper;
	@Resource
	private UserSmsMapper userSmsMapper;
	@Resource
	private ImageFilterResultMapper imageFilterResultMapper;
	@Resource
	private UserImageMapper userImageMapper;
	@Resource
	private SysConfigMapper sysConfigMapper;
	
	/**
	 * 获取用户信息
	 * @param id userId
	 * @author zq
	 */
	@ResponseBody
	@RequestMapping(value="/getUserInfo")
	public Object getUserInfo(HttpServletRequest request,String userId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				
			}else{
				userId = obj.getString("userId");
			}
			
			UserInfo userinfo  = new UserInfo();
			userinfo = userInfoService.selectByUserId(userId);
			if(userinfo==null){
				infoMap.put("resultCode", Constants.INVALID);
				infoMap.put("resultDesc", "失败");
				return infoMap;
			}
			userinfo.setNickname(PeiniUtils.updateNickName(userinfo.getNickname(),userinfo.getAccCode()));
			net.sf.json.JSONObject userInfo = net.sf.json.JSONObject.fromObject(userinfo);
			userInfo.remove("userLogin");
			userInfo.remove("birthday");
			userInfo.remove("ageTop");
			userInfo.remove("heightTop");
			userInfo.remove("weightTop");
			userInfo.remove("birthdayTop");
			userInfo.remove("reputationTop");
			userInfo.remove("reputationMonth");
			userInfo.remove("reputationYear");
			userInfo.remove("reputationQuarter");
			userInfo.remove("goldListTop");
			userInfo.remove("buyListTop");
			userInfo.remove("integrityListTop");
			userInfo.remove("userLife");
			userInfo.remove("userImage");
			userInfo.remove("userDate");
			userInfo.remove("userScore");
			userInfo.remove("selfNumTop");
			userInfo.remove("idcardNumTop");
			userInfo.remove("taskNumTop");
			userInfo.remove("regTime");
			userInfo.remove("updateTime");
			userInfo.remove("spaceBgImg");
			userInfo.remove("taskCancleCnt");
			userInfo.remove("activeTime");
			userInfo.remove("userPhone");
			userInfo.remove("blackList");
			userInfo.remove("idCardNo");
			userInfo.remove("realName");
			userInfo.remove("rechagegold");
			userInfo.remove("acctype");
			userInfo.remove("accStatus");
			userInfo.remove("userName");
			userInfo.remove("regTimeTop");
			userInfo.remove("activeTimeTop");
			userInfo.remove("taskCancleCntTop");
			userInfo.remove("bytype");
			userInfo.remove("bytype2");
			userInfo.remove("startTime");
			userInfo.remove("endTime");
			userInfo.remove("reputationQuarterTop");
			userInfo.remove("reputationMonthTop");
			userInfo.remove("userLifeTop");
			userInfo.remove("userImageTop");
			userInfo.remove("userDateTop");
			userInfo.remove("userScoreTop");
			userInfo.remove("recommendUserId");
			userInfo.remove("channel");
			userInfo.remove("devtype");
			userInfo.remove("devNo");
			userInfo.remove("imgheadUpdateTime");
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
			infoMap.put("userInfo", userInfo);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		//logger.info(new net.sf.json.JSONObject().fromObject(infoMap));
		return infoMap;
	}
	
	@ResponseBody
	@RequestMapping(value="/getNicknameAndImgHead")
	public Object getNicknameAndImgHead(HttpServletRequest request,String userId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
				
			userId = obj.getString("userId");
			
			UserInfo userInfo = userInfoService.selectByUserId(userId);
			
			if(userInfo==null){
				infoMap.put("resultCode", Constants.INVALID);
				infoMap.put("resultDesc", "失败");
				return infoMap;
			}
			LinkedHashMap<String, Object> userMap = new LinkedHashMap<String, Object>();
			userMap.put("nickname", PeiniUtils.updateNickName(userInfo.getNickname(),userInfo.getAccCode()));
			userMap.put("imageHead", StringUtils.trimToEmpty(userInfo.getImageHead()));
			
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
			infoMap.put("userInfo", userMap);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		
		return infoMap;
	}
	
	/**
	 * 获取用户信息相关字典表的数据
	 * @param id userId
	 * @author zq
	 */
	@RequestMapping(value="/getUserInfoCodes")
	@ResponseBody
	public Object getUserInfoCodes(HttpServletRequest request){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try{
			GetCode getCode = new GetCode();
			List<SystemCode> nationList = getCode.getCodeList(101);//民族
			List<SystemCode> sexList = getCode.getCodeList(102);//性别
			List<SystemCode> constellationList = getCode.getCodeList(103);//星座
			List<SystemCode> emotionList = getCode.getCodeList(104);//情感
			List<SystemCode> degreeList = getCode.getCodeList(105);//学历
			List<SystemCode> industryList = getCode.getCodeList(106);//行业
			List<SystemCode> is_houseList = getCode.getCodeList(107);//是否购房
			List<SystemCode> is_carList = getCode.getCodeList(108);//是否购车
			Object city = EhcacheUtil.getInstance().get("codeCache", "areaList");
			infoMap.put("nationList", nationList);
			infoMap.put("sexList", sexList);
			infoMap.put("constellationList", constellationList);
			infoMap.put("emotionList", emotionList);
			infoMap.put("degreeList", degreeList);
			infoMap.put("industryList",industryList);
			infoMap.put("houseList", is_houseList);
			infoMap.put("carList", is_carList);
			infoMap.put("areaCity", city);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		}catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "成功");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
		
	}
	
	/**
	 * 更新用户信息
	 * @param id 用户id,userInfo 用户条件信息
	 * @author zq
	 */
	/*@RequestMapping(value="/updateUserInfo")
	@ResponseBody
	public Object updateUserInfo(HttpServletRequest request,UserInfo userInfo){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			if (!userInfo.getNickname().isEmpty()) {
				String newNickname=ShieldTextFiltration.filter(userInfo.getNickname());
				if (!newNickname.equals(userInfo.getNickname())) {
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "您发布的信息涉及敏感字词请重新发送!");
					return infoMap;
				}
			}
			JSONObject obj = PeiniUtils.validToken(userInfo.getId());
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			
			String userId = obj.getString("userId");
			userInfo.setId(userId);
			//userInfo.setReputation(PeiniUtils.getCredit(userInfoMapper.selectByPrimaryKey(userId),1));
			//int result = userInfoService.updateByUserId(userInfo);
			int result = userInfoMapper.updateByPrimaryKeySelective(userInfo);
			if(result>0){
				UserInfo userInfoBean  = new UserInfo();
				userInfoBean = userInfoService.selectByUserId(userInfo.getId());
				int selfNum = userInfoService.getselfNum(userInfoBean);//获取资料得分
				
				UserInfo userInfoSelf = new UserInfo();
				userInfoSelf.setId(userInfoBean.getId());
				userInfoSelf.setSelfNum(selfNum);
				userInfoSelf.setUpdateTime(new Date());
				userInfoService.updateByUserId(userInfoSelf);
				
				UserInfo userInfoSelf = userInfoMapper.selectByPrimaryKey(userId);
				userInfoSelf.setSelfNum(selfNum);
				userInfoSelf.setUpdateTime(new Date());
				userInfoSelf.setReputation(PeiniUtils.getCredit(userInfoSelf,1));
				userInfoMapper.updateByPrimaryKey(userInfoSelf);
				
				userInfoBean.setSelfNum(selfNum);
				infoMap.put("userInfo", userInfoBean);
				
				//根据用户资料获取用户所适合的所有标签
				//userInfoService.updateCredit(userInfo.getId());
				List<LabelUser> labelUser = labelInfoService.goLabel(userInfo.getId());
				infoMap.put("labelSize", labelUser.size());
			}else{
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "失败");
			}
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		
		return infoMap;
	}*/
	
	/**
	 * 更新用户资料
	 * @author Han Guohong
	 * @param request
	 * @param userId
	 * @param nickname
	 * @param height
	 * @param weight
	 * @param nowProvince
	 * @param nowCity
	 * @param oldProvince
	 * @param oldCity
	 * @param constellation
	 * @param nation
	 * @param emotion
	 * @param smallIncome
	 * @param bigIncome
	 * @param degree
	 * @param industry
	 * @param isHouse
	 * @param isCar
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value="/updateUserInfo")
	public Object updateUserInfo(HttpServletRequest request,
			@RequestParam(value="id") String userId, 
			@RequestParam(value="nickname") String nickname, 
			@RequestParam(value="height",required=false) Integer height,
			@RequestParam(value="weight",required=false) Integer weight,
			@RequestParam(value="nowProvince",required=false) Integer nowProvince,
			@RequestParam(value="nowCity",required=false) Integer nowCity,
			@RequestParam(value="oldProvince",required=false) Integer oldProvince,
			@RequestParam(value="oldCity",required=false) Integer oldCity,
			@RequestParam(value="constellation",required=false) Integer constellation,
			@RequestParam(value="nation",required=false) Integer nation,
			@RequestParam(value="emotion",required=false) Integer emotion,
			@RequestParam(value="smallIncome",required=false) Integer smallIncome,
			@RequestParam(value="bigIncome",required=false) Integer bigIncome,
			@RequestParam(value="degree",required=false) Integer degree,
			@RequestParam(value="industry",required=false) Integer industry,
			@RequestParam(value="isHouse",required=false) Integer isHouse,
			@RequestParam(value="isCar",required=false) Integer isCar
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "资料完善成功！");
		try {
			if (StringUtils.isNotBlank(nickname)) {
				String newNickname=ShieldTextFiltration.filter(nickname);
				if (!newNickname.equals(nickname)) {
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "您发布的信息涉及敏感字词请重新发送!");
					return infoMap;
				}
			}
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			
			userId = obj.getString("userId");
			UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
			userInfo.setNickname(nickname);
			userInfo.setHeight(height);
			userInfo.setWeight(weight);
			userInfo.setNowProvince(nowProvince);
			userInfo.setNowCity(nowCity);
			userInfo.setOldProvince(oldProvince);
			userInfo.setOldCity(oldCity);
			userInfo.setConstellation(constellation);
			userInfo.setNation(nation);
			userInfo.setEmotion(emotion);
			userInfo.setSmallIncome(smallIncome);
			userInfo.setBigIncome(bigIncome);
			userInfo.setDegree(degree);
			userInfo.setIndustry(industry);
			userInfo.setIsHouse(isHouse);
			userInfo.setIsCar(isCar);
			
			int selfNum = userInfoService.getselfNum(userInfo);//获取资料得分
			userInfo.setSelfNum(selfNum);
			userInfo.setUpdateTime(new Date());
			userInfo.setReputation(PeiniUtils.getCredit(userInfo,0));
			userInfoMapper.updateByPrimaryKeySelective(userInfo);
			
			PeiniUtils.getCredit(userInfo,1);
			userInfo.setNickname(PeiniUtils.updateNickName(userInfo.getNickname(),userInfo.getAccCode()));
			net.sf.json.JSONObject userinfo = net.sf.json.JSONObject.fromObject(userInfo);
			userinfo.remove("userLogin");
			userinfo.remove("birthday");
			userinfo.remove("ageTop");
			userinfo.remove("heightTop");
			userinfo.remove("weightTop");
			userinfo.remove("birthdayTop");
			userinfo.remove("reputationTop");
			userinfo.remove("reputationMonth");
			userinfo.remove("reputationYear");
			userinfo.remove("reputationQuarter");
			userinfo.remove("goldListTop");
			userinfo.remove("buyListTop");
			userinfo.remove("integrityListTop");
			userinfo.remove("userLife");
			userinfo.remove("userImage");
			userinfo.remove("userDate");
			userinfo.remove("userScore");
			userinfo.remove("selfNumTop");
			userinfo.remove("idcardNumTop");
			userinfo.remove("taskNumTop");
			userinfo.remove("regTime");
			userinfo.remove("updateTime");
			userinfo.remove("spaceBgImg");
			userinfo.remove("taskCancleCnt");
			userinfo.remove("activeTime");
			userinfo.remove("userPhone");
			userinfo.remove("blackList");
			userinfo.remove("idCardNo");
			userinfo.remove("realName");
			userinfo.remove("rechagegold");
			userinfo.remove("acctype");
			userinfo.remove("accStatus");
			userinfo.remove("userName");
			userinfo.remove("regTimeTop");
			userinfo.remove("activeTimeTop");
			userinfo.remove("taskCancleCntTop");
			userinfo.remove("bytype");
			userinfo.remove("bytype2");
			userinfo.remove("startTime");
			userinfo.remove("endTime");
			userinfo.remove("reputationQuarterTop");
			userinfo.remove("reputationMonthTop");
			userinfo.remove("userLifeTop");
			userinfo.remove("userImageTop");
			userinfo.remove("userDateTop");
			userinfo.remove("userScoreTop");
			userinfo.remove("recommendUserId");
			userinfo.remove("channel");
			userinfo.remove("devtype");
			userinfo.remove("devNo");
			userinfo.remove("imgheadUpdateTime");
			infoMap.put("userInfo", userinfo);
			
			List<LabelUser> labelUser = labelInfoService.goLabel(userInfo.getId());
			infoMap.put("labelSize", labelUser.size());
			
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		
		return infoMap;
	}
	
	/**
	 * 更新用户签名信息
	 * @param id 用户id,signWord 签名
	 * @author zq
	 */
	@RequestMapping(value="/updateUserSignWord")
	@ResponseBody
	public Object updateUserSignWord(HttpServletRequest request,UserInfo userInfo){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
//			if (!userInfo.getSignWord().isEmpty()) {
//				String newSignWord=ShieldTextFiltration.filter(userInfo.getSignWord());
//				if (!newSignWord.equals(userInfo.getSignWord())) {
//					infoMap.put("resultCode", Constants.FAIL);
//					infoMap.put("resultDesc", "您发布的信息涉及敏感字词请重新发送!");
//					return infoMap;
//				}
//			}
			JSONObject obj = PeiniUtils.validToken(userInfo.getId());
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userInfo.setId(obj.getString("userId"));
			
			//int result = userInfoService.updateByUserId(userInfo);
			int result = userInfoMapper.updateByPrimaryKeySelective(userInfo);
			if(result>0){
				UserInfo userInfoBean  = new UserInfo();
				userInfoBean = userInfoService.selectByUserId(userInfo.getId());
				infoMap.put("signWord", userInfoBean.getSignWord());
			}else{
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "失败");
			}
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		
		return infoMap;
	}
	
	/**
	 * 更改个人空间背景图像
	 * @param request
	 * @param userToken
	 * @param file
	 * @return
	 */
	@RequestMapping(value="/updateUserBgImg")
	@ResponseBody
	public Object updateUserBgImg(HttpServletRequest request,
			@RequestParam(value="userToken") String userToken,
			//@RequestParam(value="file",required=false) MultipartFile file,
			@RequestParam(value="filePath",required=false) String filePath
			) throws Exception{
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			MultipartFile file = null;
			if(request instanceof MultipartHttpServletRequest){
				file = ((MultipartHttpServletRequest) request).getFile("file");
			}
			
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
			
			JSONObject obj = PeiniUtils.validToken(userToken);
			if(obj.getInteger("resultCode") != 1){
				return obj.toString();
			}
			String userId = obj.getString("userId");
			
			UserInfo info = new UserInfo();
			info.setId(userId);
			
			if (file != null && !file.isEmpty()) {
				filePath = "/upload/spaceBgImg/";
				String resultPath = FileUtils.uploadFile(file, filePath);
				info.setSpaceBgImg(resultPath);
				
				ImgVo imgVo = new ImgVo();
				imgVo.setImgUrl(resultPath);
				imgVo.setParamId(info.getId());
				imgVo.setType(5);
				RedisUtil.lpush(RedisConstants.IMG_CHECK.getBytes(), SerializeUtil.serialize(imgVo));
				/*Integer result = ImageFilterUtil.checkImg(file);
				if(result == 0 || result == 1){
					String resultPath = FileUtils.uploadFile(file, filePath);
					info.setSpaceBgImg(resultPath);
					
					if(result == 1){
						ImageFilterResult image = new ImageFilterResult();
						image.setImgurl(resultPath);
						image.setUrltype("spaceBgImg");
						imageFilterResultMapper.insert(image);
					}
				}*/
			}else{
				info.setSpaceBgImg(filePath);
			}
			
			userInfoService.updateByPrimaryKeySelective(info);
			
			infoMap.put("spaceBgImg", info.getSpaceBgImg());
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		
		return infoMap;
	}
	
	
	/**
	 * 更新用户头像信息
	 * @param userId 用户id
	 * @author zq
	 */
	@RequestMapping(value="/updateUserImageHead",method = RequestMethod.POST)
	@ResponseBody
	public Object updateUserImageHead(HttpServletRequest request,@RequestParam("file") MultipartFile file,String userId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "头像上传成功！");
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			// 判断文件是否为空  
	        if (!file.isEmpty()) {
	        	
	        	HashMap<String, Object> userMap = userInfoService.getUserInfoAndLoginAccountInfo(userId);
	        	
				String filePath = "/upload/headImg/"+userMap.get("mobileNo").toString()+".png";
				
				UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
		        
		        String resultPath = "";
		        
		        resultPath = FileUtils.uploadFile(file, filePath);
				userInfo.setImageHead(resultPath);
				userInfo.setImgheadUpdateTime(new Date());
				userInfo.setImgheadIsdelete(0);
				
				userInfoMapper.updateByPrimaryKey(userInfo);
				
				ImgVo imgVo = new ImgVo();
				imgVo.setImgUrl(resultPath);
				imgVo.setParamId(userId);
				imgVo.setType(2);
				RedisUtil.lpush(RedisConstants.IMG_CHECK.getBytes(), SerializeUtil.serialize(imgVo));
		        
		        infoMap.put("imageUrl",resultPath);
		        
		        //消息推送
				JSONObject object = new JSONObject();
				object.put("title", "系统消息");
				object.put("content", "恭喜您头像上传成功！陪你小秘书正马不停蹄地为您审核头像，审核期间除任务互动外，其他功能均能正常使用哦~");
				object.put("paramId", userInfo.getId());
				object.put("type", 203);
				AppPush.sendPush(object,userInfo.getUserPhone().split(","));
				
				SmsSendUtil.sendSmsFit(null, userInfo.getId(), userInfo.getId().toString(), 203, "恭喜您头像上传成功！陪你小秘书正马不停蹄地为您审核头像，审核期间除任务互动外，其他功能均能正常使用哦~");
	        }else{
	        	infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "失败");
				infoMap.put("imageUrl","");
	        }
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		
		return infoMap;
	}
	
//	/**
//	 * 获取用户头像信息
//	 * @param userId 用户id
//	 * @author zq
//	 * @throws IOException 
//	 */
//	@RequestMapping(value="/getUserImageHead/{userId}")
//	public String getUserImageHead(HttpServletRequest request,HttpServletResponse response,@PathVariable("userId") int userId) throws IOException{
//		response.setContentType("image/png"); // 设置返回内容格式
//		String picurl = request.getSession().getServletContext().getRealPath("/") + "img/noimage.png";//设置如果没有图片默认的显示
//		UserInfo userInfo = userInfoService.selectByUserId(userId);
//		//如果头像信息不为空
//		if(StringUtils.isNotBlank(userInfo.getImageHead())){
//			picurl = userInfo.getImageHead();
//		}
//		File file = new File(picurl);
//		if(file.exists()){   //如果文件存在
//			InputStream in = new FileInputStream(picurl);   //用该文件创建一个输入流
//			OutputStream os = response.getOutputStream();  //创建输出流
//			byte[] b = new byte[1024];  
//			while( in.read(b)!= -1){ 
//			os.write(b);     
//			}
//			in.close(); 
//			os.flush();
//			os.close();
//		}
//		return null;
//	}
	
	/**
	 * 获取用户头像信息
	 * @param userId 用户id
	 * @author zq
	 * @throws IOException 
	 */
	@RequestMapping(value="/getImageHead")
	public String getImageHead(HttpServletRequest request,HttpServletResponse response,String userId) throws IOException{
		response.setContentType("image/png"); // 设置返回内容格式
		String picurl = request.getSession().getServletContext().getRealPath("/") + "img/noimage.png";//设置如果没有图片默认的显示
		UserInfo userInfo = userInfoService.selectByUserId(userId);
		//如果头像信息不为空
		if(StringUtils.isNotBlank(userInfo.getImageHead())){
			picurl = userInfo.getImageHead();
		}
		File file = new File(picurl);
		if(file.exists()){   //如果文件存在
			InputStream in = new FileInputStream(picurl);   //用该文件创建一个输入流
			OutputStream os = response.getOutputStream();  //创建输出流
			byte[] b = new byte[1024];  
			while( in.read(b)!= -1){ 
			os.write(b);     
			}
			in.close(); 
			os.flush();
			os.close();
		}
		return null;
	}
	
	/**
	 * 我的空间详细资料查看
	 * @param userId 用户id
	 * @author zq
	 */
	@RequestMapping(value="/getUserAllInfo")
	@ResponseBody
	public Object getUserAllInfo(HttpServletRequest request,
			@RequestParam(value="userToken") String userToken
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		LinkedHashMap<String, Object> otherInfo = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			
			if(StringUtils.isBlank(userToken)){
				infoMap.put("resultCode", Constants.INVALID);
				infoMap.put("resultDesc", "token失效");
				return infoMap;
			}
			
			JSONObject obj = PeiniUtils.validToken(userToken);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			String userId = obj.getString("userId");
			
			UserInfo userInfo  = new UserInfo();
			userInfo = userInfoService.selectByUserId(userId);
			
			if(!PeiniUtils.isAddUserInfo(userInfo)){
				infoMap.put("resultCode", Constants.INFO_INVALIDATE);
				infoMap.put("resultDesc", "必要资料不全，请完善资料");
				return infoMap;
			}
			
			HashMap<String, String> userMap = new HashMap<String, String>();
			
			userMap.put("imageHead", StringUtils.trimToEmpty(userInfo.getImageHead()));
			userMap.put("spaceBgImg", StringUtils.trimToEmpty(userInfo.getSpaceBgImg()));
			userMap.put("nickname", PeiniUtils.updateNickName(StringUtils.trimToEmpty(userInfo.getNickname()), StringUtils.trimToEmpty(userInfo.getAccCode())));
			userMap.put("signWord", StringUtils.trimToEmpty(userInfo.getSignWord()));
			userMap.put("age", userInfo.getAge() == null ? "" : userInfo.getAge().toString());
			userMap.put("nowProvinceText", StringUtils.trimToEmpty(userInfo.getNowProvinceText()));
			userMap.put("nowCityText", StringUtils.trimToEmpty(userInfo.getNowCityText()));
			userMap.put("accCode", StringUtils.trimToEmpty(userInfo.getAccCode()));
			userMap.put("goldList", userInfo.getGoldList() == null ? "" : userInfo.getGoldList().toString());
			userMap.put("buyList", userInfo.getBuyList() == null ? "" : userInfo.getBuyList().toString());
			userMap.put("integrityList", userInfo.getIntegrityList() == null ? "" : userInfo.getIntegrityList().toString());
			userMap.put("isPhone", userInfo.getIsPhone() == null ? "0" : userInfo.getIsPhone().toString());
			userMap.put("isIdCard", userInfo.getIsIdcard() == null ? "0" : userInfo.getIsIdcard().toString());
			userMap.put("is_video", userInfo.getIsVideo() == null ? "0" : userInfo.getIsVideo().toString());
			userMap.put("sex", userInfo.getSex() == null ? "" : userInfo.getSex().toString());
			
			//获取用户基本信息
			if(StringUtils.isBlank(userInfo.getSignWord())){
				userInfo.setSignWord("");
			}
			infoMap.put("userInfo", userMap);
			
			//判断是否签到
			SignInfo signInfo = new SignInfo();
			signInfo.setUserId(userId);
			Date now = new Date(); 
			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
			
			String today = dateFormat.format(now)+" 00:00:00";
			Date nowD = dateFormat.parse(today);
			
			signInfo.setSignDate(nowD);
			SignInfo signMap = signInfoService.selectTodayByUser(signInfo);
			if(signMap!=null){
				otherInfo.put("signStatus", 1);//今日已签到返回1
			}else{
				otherInfo.put("signStatus", 0);
			}
			
			//资料完整度
			int selfCount = userInfo.getSelfNum();
			otherInfo.put("selfCount", selfCount);
			
			//信用值
			int credit = userInfoService.getCredit(userInfo);
			otherInfo.put("credit", PeiniUtils.getCredit(userInfo,0));
			
			//获取我关注的人
			int myConcern = userConcernService.selectCountMyConcern(userId);
			otherInfo.put("myConcern", myConcern);
			//获取我的粉丝
			int myFans = userConcernService.selectCountMyFans(userId);
			otherInfo.put("myFans", myFans);
			
			//获取账户信息
			UserAccount userAccount = userAccountService.selectByUserId(userId);
			otherInfo.put("gold", (double)userAccount.getGold()/100);//金币
			otherInfo.put("score", userAccount.getScore());//积分
			
			//获取相册图片路径
			List<HashMap<String,Object>> imageList = userImageService.selectByUserId(userId);
			infoMap.put("imageList", imageList);
			
			UserImageExample imageExample = new UserImageExample();
			imageExample.createCriteria().andUserIdEqualTo(userId);
			Long imgCnt = userImageMapper.countByExample(imageExample);
			infoMap.put("imgCnt", imgCnt);
			
			//用户标签
			List<LinkedHashMap<String,Object>> lableList = labelInfoService.selectLabelUserByUserInfoId(userId);
			infoMap.put("lableList", lableList);
			
			//最后一次发布任务
			HashMap<String,Object> taskLastInfo = taskInfoService.getTaskLast(userId);
			if(taskLastInfo == null){
				taskLastInfo = new HashMap<String, Object>();
			}//else{
				//任务达成度
				/*int taskCancle = taskInfoService.getCancelNum(userId);
				taskLastInfo.put("taskScore", 100-taskCancle);*/
			List<Integer> statusList = new ArrayList<Integer>();
			TaskInfoExample example = new TaskInfoExample();
			com.jsz.peini.bean.task.TaskInfoExample.Criteria criteria = example.createCriteria();
			statusList.add(1);
			statusList.add(2);
			statusList.add(3);
			statusList.add(4);
			statusList.add(5);
			statusList.add(7);
			criteria.andTaskStatusIn(statusList);
			criteria.andUserIdEqualTo(userId);
			
			statusList = new ArrayList<Integer>();
			com.jsz.peini.bean.task.TaskInfoExample.Criteria criteria2 = example.createCriteria();
			statusList.add(21);
			statusList.add(31);
			statusList.add(41);
			statusList.add(5);
			statusList.add(6);
			criteria2.andTaskOtherStatusIn(statusList);
			criteria2.andOtherUserIdEqualTo(userId);
			example.or(criteria2);
			
			/*TaskInfoExample example = new TaskInfoExample();
			com.jsz.peini.bean.task.TaskInfoExample.Criteria criteria = example.createCriteria();
			criteria.andUserIdEqualTo(userId);
			
			com.jsz.peini.bean.task.TaskInfoExample.Criteria criteria2 = example.createCriteria();
			criteria2.andOtherUserIdEqualTo(userId);
			example.or(criteria2);*/
			
			Long finishCnt = taskInfoMapper.countByExample(example);
			
			example = new TaskInfoExample();
			criteria = example.createCriteria();
			criteria.andTaskCancleTypeNotEqualTo(3);//系统取消
			criteria.andTaskCancleTypeNotEqualTo(2);//双方原因取消
			criteria.andCancelUserIdEqualTo(userId);
			
			Long cancleCnt = taskInfoMapper.countByExample(example);
			
			Long totalCnt = finishCnt;
			if(totalCnt == 0){
				taskLastInfo.put("taskScore", 0);
			}else{
				long num = (long)(((double)finishCnt-cancleCnt)/(finishCnt)*100);
				if(num == 0){
					taskLastInfo.put("taskScore", "0");
				}else{
					taskLastInfo.put("taskScore", num);
				}
				/*DecimalFormat df = new DecimalFormat("######0.00");
				double num = ((double)finishCnt-cancleCnt)/(finishCnt)*100;
				if(num == 0){
					taskLastInfo.put("taskScore", "0");
				}else{
					taskLastInfo.put("taskScore", df.format(num));
				}
				taskLastInfo.put("taskScore", Double.parseDouble(taskLastInfo.get("taskScore").toString()));*/
			}
			
			if(taskLastInfo.get("sellerBigType") == null){
				taskLastInfo.put("sellerTypeImg","");
			}else{
				taskLastInfo.put("sellerTypeImg", PeiniUtils.yetaiMap.get(taskLastInfo.get("sellerBigType").toString()).getImageSrc());
			}
				//taskLastInfo.put("sellerTypeImg", PeiniUtils.yetaiMap.get(taskLastInfo.get("sellerBigType").toString()).getImageSrc());
			//}
			
			infoMap.put("taskLastInfo", taskLastInfo);
			
			//最后一条广场信息
			HashMap<String,Object> squareLastInfo = squareInfoService.selectLastByUserId(userId);
			if(squareLastInfo == null){
				squareLastInfo = new HashMap<String, Object>();
			}else{
				List<LinkedHashMap<String,Object>> imgList = squareInfoService.selectsquareImageBySquareInfoId(Integer.parseInt(squareLastInfo.get("squareId").toString()));
				String str = "";
				for (LinkedHashMap<String, Object> imgMap : imgList) {
					str += imgMap.get("imageSrc").toString()+",";
				}
				squareLastInfo.put("imageSrc", str);
			}
			infoMap.put("squareLastInfo", squareLastInfo);	
			
			infoMap.put("otherInfo", otherInfo);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		//logger.info(net.sf.json.JSONObject.fromObject(infoMap));
		return infoMap;
	}
	
	/**
	 * 他人空间资料查看
	 * @param userId 他人id,myId 用户id
	 * @author zq
	 */
	@RequestMapping(value="/getUserInfoByOtherId")
	@ResponseBody
	public Object getUserInfoByOtherId(HttpServletRequest request,String userId,String myId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		LinkedHashMap<String, Object> otherInfo = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			UserInfo userInfo  = new UserInfo();
			
//			JSONObject obj = PeiniUtils.validToken(myId);
//			if(obj.getInteger("resultCode") != 1){
//				return obj;
//			}
//			myId = obj.getString("userId");
			
			userInfo = userInfoService.selectByUserId(userId);
			UserInfo myInfo = userInfoService.selectByUserId(userId);
			
			//获取用户基本信息
			HashMap<String, Object> userMap = new HashMap<String, Object>();
			userMap.put("id", userInfo.getId());
			userMap.put("userLoginId", userInfo.getUserLoginId());
			userMap.put("nickname",PeiniUtils.updateNickName(userInfo.getNickname(),userInfo.getAccCode()));
			userMap.put("signWord", StringUtils.trimToEmpty(userInfo.getSignWord()));
			userMap.put("imageHead", StringUtils.trimToEmpty(userInfo.getImageHead()));
			userMap.put("sex", userInfo.getSex() == null ? "" : userInfo.getSex().toString());
			userMap.put("birthday", userInfo.getBirthday() == null ? "" : userInfo.getBirthday());
			userMap.put("age", userInfo.getAge() == null ? "" : userInfo.getAge().toString());
			userMap.put("nowProvinceText", StringUtils.trimToEmpty(userInfo.getNowProvinceText()));
			userMap.put("nowCityText", StringUtils.trimToEmpty(userInfo.getNowCityText()));
			userMap.put("userPhone", userInfo.getUserPhone());
			userMap.put("selfNum", userInfo.getSelfNum());
			userMap.put("idcardNum", userInfo.getIdcardNum());
			userMap.put("taskNum", userInfo.getTaskNum());
			userMap.put("accCode", StringUtils.trim(userInfo.getAccCode()));
			userMap.put("goldList", userInfo.getGoldList());
			userMap.put("buyList", userInfo.getBuyList());
			userMap.put("integrityList", userInfo.getIntegrityList());
			userMap.put("isPhone", userInfo.getIsPhone());
			userMap.put("isIdcard", userInfo.getIsIdcard());
			userMap.put("isIdCard", userInfo.getIsIdcard());
			userMap.put("isVideo", userInfo.getIsVideo());
			userMap.put("isVideo", userInfo.getIsVideo());
			userMap.put("spaceBgImg", StringUtils.trimToEmpty(userInfo.getSpaceBgImg()));
			userMap.put("is_video", userInfo.getIsVideo());
			userMap.put("industryText", StringUtils.trimToEmpty(userInfo.getIndustryText()));
			
			infoMap.put("userInfo", userMap);
			
			UserConcern userConcern = new UserConcern();
			userConcern.setUserId(myId);
			userConcern.setOtherId(userId);
			UserConcern concernMap = userConcernService.selectNum(userConcern);
			if(concernMap!=null){
				otherInfo.put("isConcern", 1);//已关注
			}else{
				otherInfo.put("isConcern", 0);//未关注
			}
			
			//获取他关注的人
			int myConcern = userConcernService.selectCountMyConcern(userId);
			otherInfo.put("myConcern", myConcern);
			//获取他的粉丝
			int myFans = userConcernService.selectCountMyFans(userId);
			otherInfo.put("myFans", myFans);
			
			//资料完整度
			int selfCount = userInfo.getSelfNum() == null ? 0 : userInfo.getSelfNum();
			otherInfo.put("selfCount", selfCount);
			
			//信用值
			int credit = userInfoService.getCredit(userInfo);
			otherInfo.put("credit", credit);
			
			//我的信用值
			int mycredit = userInfoService.getCredit(myInfo);
			otherInfo.put("mycredit", mycredit);
			
			//获取相册图片路径
			List<HashMap<String,Object>> imageList = userImageService.selectByUserId(userId);
			infoMap.put("imageList", imageList);
			
			UserImageExample imageExample = new UserImageExample();
			imageExample.createCriteria().andUserIdEqualTo(userId);
			Long imgCnt = userImageMapper.countByExample(imageExample);
			infoMap.put("imgCnt", imgCnt);
			
			//用户标签
			List<LinkedHashMap<String,Object>> lableList = labelInfoService.selectLabelUserByUserInfoId(userId);
			infoMap.put("lableList", lableList);
			
			//最后一次发布任务
			HashMap<String,Object> taskLastInfo = taskInfoService.getTaskLast(userId);
			if(taskLastInfo == null){
				//infoMap.put("taskLastInfo", new HashMap<String,Object>());
				taskLastInfo = new HashMap<String, Object>();
			}/*else{
				//任务达成度
				int taskCancle = taskInfoService.getCancelNum(userId);
				taskLastInfo.put("taskScore", 100-taskCancle);
				infoMap.put("taskLastInfo", taskLastInfo);
			}*/
			
			TaskInfoExample example = new TaskInfoExample();
			com.jsz.peini.bean.task.TaskInfoExample.Criteria criteria = example.createCriteria();
			criteria.andUserIdEqualTo(userId);
			
			com.jsz.peini.bean.task.TaskInfoExample.Criteria criteria2 = example.createCriteria();
			criteria2.andOtherUserIdEqualTo(userId);
			example.or(criteria2);
			
			Long finishCnt = taskInfoMapper.countByExample(example);
			
			example = new TaskInfoExample();
			criteria = example.createCriteria();
			criteria.andTaskCancleTypeNotEqualTo(3);//系统取消
			criteria.andTaskCancleTypeNotEqualTo(2);//双方原因取消
			criteria.andCancelUserIdEqualTo(userId);
			
			Long cancleCnt = taskInfoMapper.countByExample(example);
			
			Long totalCnt = finishCnt;
			if(totalCnt == 0){
				taskLastInfo.put("taskScore", 0);
			}else{
				long num = (long)(((double)finishCnt-cancleCnt)/(finishCnt)*100);
				if(num == 0){
					taskLastInfo.put("taskScore", "0");
				}else{
					taskLastInfo.put("taskScore", num);
				}
				/*DecimalFormat df = new DecimalFormat("#######.##");
				double num = ((double)finishCnt-cancleCnt)/(finishCnt)*100;
				if(num == 0){
					taskLastInfo.put("taskScore", "0");
				}else{
					taskLastInfo.put("taskScore", df.format(num));
				}
				taskLastInfo.put("taskScore", Double.parseDouble(taskLastInfo.get("taskScore").toString()));*/
			}
			
			if(taskLastInfo.get("sellerBigType") == null){
				taskLastInfo.put("sellerTypeImg","");
			}else{
				taskLastInfo.put("sellerTypeImg", PeiniUtils.yetaiMap.get(taskLastInfo.get("sellerBigType").toString()).getImageSrc());
			}
			
			infoMap.put("taskLastInfo", taskLastInfo);
			
			//最后一条广场信息
			HashMap<String,Object> squareLastInfo = squareInfoService.selectLastByUserId(userId);
			if(squareLastInfo == null){
				squareLastInfo = new HashMap<String, Object>();
			}else{
				List<LinkedHashMap<String,Object>> imgList = squareInfoService.selectsquareImageBySquareInfoId(Integer.parseInt(squareLastInfo.get("squareId").toString()));
				String str = "";
				for (LinkedHashMap<String, Object> imgMap : imgList) {
					str += imgMap.get("imageSrc").toString()+",";
				}
				squareLastInfo.put("imageSrc", str);
			}
			infoMap.put("squareLastInfo", squareLastInfo);
			
			infoMap.put("otherInfo", otherInfo);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "失败");
			logger.error(e.getMessage(),e);
		}
		
		/*net.sf.json.JSONObject object = net.sf.json.JSONObject.fromObject(infoMap);
		net.sf.json.JSONObject userObject = object.getJSONObject("userInfo");
		if(userObject.containsKey("isIdcard")){
			userObject.put("isIdCard", userObject.getInt("isIdcard"));
			object.put("userInfo", userObject);
		}*/
		
		return infoMap;
	}

	/**
	 * 关注他人
	 * @param userId 用户id,otherId 被关注人id
	 * @author zq
	 * @throws IOException 
	 */
	@RequestMapping(value="/goConcern")
	@ResponseBody
	public Object goConcern(HttpServletRequest request,UserConcern userConcern){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			
			JSONObject obj = PeiniUtils.validToken(userConcern.getUserId());
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			String userId = obj.getString("userId");
			userConcern.setUserId(userId);
			
			UserConcern concernMap = userConcernService.selectNum(userConcern);
			//如果有关注过则取消关注
			if(concernMap!=null){
				userConcernService.delete(concernMap);				
				/*infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "重复关注");*/
			}else{
				userConcern.setCreateTime(new Date());
				userConcernService.insert(userConcern);
				
				/*UserSms userSms = new UserSms();
				userSms.setSmsid(UUID.randomUUID().toString().replace("-", ""));
				userSms.setIsremind(1);
				userSms.setParamid(userConcern.getId().toString());
				userSms.setReceivdel(0);
				userSms.setSenddel(0);
				userSms.setSendtime(new Date());
				userSms.setSmscontent("刚刚有人关注您啦!");
				userSms.setSmstype(9);
				userSms.setToid(userConcern.getOtherId().toString());
				userSmsMapper.insertSelective(userSms);*/
				SmsSendUtil.sendSmsNotify(userConcern.getOtherId().toString(), userId.toString(), 9, "刚刚有人关注您啦!");
			}
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求异常");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 取消关注
	 * @param userId 用户id,otherId 被关注人id
	 * @author zq
	 * @throws IOException 
	 */
	@RequestMapping(value="/delConcern")
	@ResponseBody
	public Object delConcern(HttpServletRequest request,UserConcern userConcern){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			UserConcern concernMap = userConcernService.selectNum(userConcern);
			//如果有关注过则删除
			if(concernMap!=null){
				userConcernService.delete(concernMap);
			}else{
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "重复取消关注");
			}
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求异常");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 我关注的
	 * @param userId 用户id
	 * @author zq
	 * @throws IOException 
	 */
	@ApiOperation("关注列表")
	@RequestMapping(value="/myConcern", method=RequestMethod.POST)
	@ResponseBody
	public Object myConcern(HttpServletRequest request,String userId,
			@RequestParam(value="page",defaultValue="1") Integer page,
			@RequestParam(value="rows") Integer rows
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			PageHelper.startPage(page, rows);
			List<LinkedHashMap<String,Object>> objectList = userConcernService.selectMyConcern(userId);
			
			infoMap.put("objectList", objectList);
			List<LinkedHashMap<String,Object>> myFans = userConcernService.selectMyFans(userId);
			infoMap.put("fansNum", myFans.size());
			if(myFans.size()>0){
				infoMap.put("imageHead", myFans.get(0).get("imageHead")==null?"":myFans.get(0).get("imageHead"));
			}else{
				infoMap.put("imageHead", "");
			}
			UserInfo userInfo = userInfoService.selectByUserId(userId);
			infoMap.put("myImageHead", StringUtils.isBlank(userInfo.getImageHead())?"":userInfo.getImageHead());
			infoMap.put("myNickname", PeiniUtils.updateNickName(userInfo.getNickname(),userInfo.getAccCode()));
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求异常");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 我的粉丝
	 * @param userId 用户id
	 * @author zq
	 * @throws IOException 
	 */
	@ApiOperation("粉丝列表")
	@RequestMapping(value="/myFans", method=RequestMethod.POST)
	@ResponseBody
	public Object myFans(HttpServletRequest request,String userId,
			@RequestParam(value="page",defaultValue="1") Integer page,
			@RequestParam(value="rows") Integer rows){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			PageHelper.startPage(page,rows);
			List<LinkedHashMap<String,Object>> objectList = userConcernService.selectMyFans(userId);
			for (int i = 0; i < objectList.size(); i++) {
				objectList.get(i).put("nickname",PeiniUtils.updateNickName(objectList.get(i).get("nickname").toString(),objectList.get(i).get("accCode").toString()));
			}
			infoMap.put("objectList", objectList);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求异常");
			logger.error(e.getMessage(),e);
		}
		//logger.info(net.sf.json.JSONObject.fromObject(infoMap));
		return infoMap;
	}
	
	
	
	
	/**
	 * 我的好友
	 * @param userId 用户id
	 * @author zq
	 * @throws IOException 
	 */
	@ApiOperation("好友列表")
	@RequestMapping(value="/myFriends", method=RequestMethod.POST, consumes="application/x-www-form-urlencoded")
	@ResponseBody
	public Object myFriends(HttpServletRequest request,
			@RequestParam(value="userId")String userId,
			@RequestParam(value="page",defaultValue="1") Integer page,
			@RequestParam(value="rows") Integer rows){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			PageHelper.startPage(page,rows);
			List<LinkedHashMap<String,Object>> objectList = userConcernService.selectMyFriends(userId);
			for (int i = 0; i < objectList.size(); i++) {
				objectList.get(i).put("nickname",PeiniUtils.updateNickName(objectList.get(i).get("nickname").toString(),objectList.get(i).get("accCode").toString()));
			}
			infoMap.put("objectList", objectList);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求异常");
			logger.error(e.getMessage(),e);
		}
		//logger.info(net.sf.json.JSONObject.fromObject(infoMap));
		return infoMap;
	}
	
	/**
	 * 是否关注
	 * @param userId 用户id,otherId 被关注人id
	 * @author zq
	 * @throws IOException 
	 */
	@RequestMapping(value="/isConcern")
	@ResponseBody
	public Object isConcern(HttpServletRequest request,UserConcern userConcern){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			UserConcern concernMap = userConcernService.selectNum(userConcern);
			if(concernMap!=null){
				infoMap.put("obj", 1);//已关注
			}else{
				infoMap.put("obj", 0);//未关注
			}
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求异常");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 身份实名认证
	 * @param request
	 * @param userId
	 * @param idcardName  身份证姓名
	 * @param idcardId 身份证号码
	 * @return
	 */
	@RequestMapping(value="/isIdcard")
	@ResponseBody
	public Object isIdcard(HttpServletRequest request,String userId,String idcardName,String idcardId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			infoMap.put("idcardName", idcardName);
			infoMap.put("idcardId", idcardId);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");   
			String json=IdCardSend.checkCard(idcardName, idcardId);
			JSONObject json1=JSON.parseObject(json);
			
			if(json1.getIntValue("status") == 0){
				JSONObject jso=(JSONObject)json1.get("result");
				if(jso.getInteger("verifystatus") == 1){
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", jso.getString("verifymsg"));    
					return infoMap;
				}else if(jso.getInteger("verifystatus") == 0){
					UserInfoExample example = new UserInfoExample();
					example.createCriteria().andIdcardnoEqualTo(idcardId);
					List<UserInfo> userList = userInfoMapper.selectByExampleWithBLOBs(example);
					if(userList.size() > 0){
						infoMap.put("resultCode", Constants.FAIL);
						infoMap.put("resultDesc", "该身份证号已经被认证过了！");    
						return infoMap;
					}
					
					UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
					userInfo.setIdCardNo(idcardId);
					userInfo.setRealName(idcardName);
					userInfo.setIsIdcard(1);
					userInfo.setIdcardNum(100);
					userInfo.setUpdateTime(new Date());
					userInfo.setReputation(PeiniUtils.getCredit(userInfo,1));
					
					int updateNum = userInfoMapper.updateByPrimaryKeySelective(userInfo);
					if (updateNum>0) {
						UserVo userVo = UserRedisUtil.getUserVoByUserId(userId);
						if(userVo != null){
							userVo.setIdCardNo(idcardId);
						}
						UserRedisUtil.addUserToRedis(userVo);
						
						infoMap.put("resultCode", Constants.SUCCESS);
						infoMap.put("resultDesc", "成功");    
					}
				}
			}else{
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", json1.getString("msg"));    
				return infoMap;
			}
			
			/*JSONObject jso=(JSONObject)json1.get("result");
			String jsoNum = (String)jso.get("verifystatus");
			if (jsoNum.equals("0")) {
				UserInfoExample example = new UserInfoExample();
				example.createCriteria().andIdcardnoEqualTo(idcardId);
				List<UserInfo> userList = userInfoMapper.selectByExampleWithBLOBs(example);
				if(userList.size() > 0){
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "该身份证号已经被认证过了！");    
					return infoMap;
				}
				
				UserInfo userInfo = userInfoMapper.selectByPrimaryKey(userId);
				userInfo.setIdCardNo(idcardId);
				userInfo.setRealName(idcardName);
				userInfo.setIsIdcard(1);
				userInfo.setIdcardNum(100);
				userInfo.setUpdateTime(new Date());
				userInfo.setReputation(PeiniUtils.getCredit(userInfo,1));
				int updateNum = userInfoMapper.updateByPrimaryKeySelective(userInfo);
				if (updateNum>0) {
					UserVo userVo = UserRedisUtil.getUserVoByUserId(userId);
					if(userVo != null){
						userVo.setIdCardNo(idcardId);
					}
					UserRedisUtil.addUserToRedis(userVo);
					
					infoMap.put("resultCode", Constants.SUCCESS);
					infoMap.put("resultDesc", "成功");    
				}
			}else{
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "认证失败");    
			}*/
	    } catch (Exception e) {
	    	infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "认证失败"); 
	    	logger.error(e.getMessage(),e);
	    }
		return infoMap;
	}
	

	/**
	 * 信用对比
	 * @param userId 用户id,otherId 对方id(不查询的话)
	 * @return
	 */
	@RequestMapping(value="/getCredit")
	@ResponseBody
	public Object getCredit(HttpServletRequest request,String userId,String otherId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			HashMap<String,Object> myCredit = new HashMap<String,Object>();
			HashMap<String,Object> otherCredit = new HashMap<String,Object>();
			if(StringUtils.isNotBlank(otherId)){
				//UserInfo otherInfo = userInfoService.selectByUserId(otherId);
				UserInfo otherInfo = userInfoService.selectByPrimaryKey(otherId);
				otherCredit.put("nickName",PeiniUtils.updateNickName(otherInfo.getNickname(),otherInfo.getAccCode()) );
				otherCredit.put("imgHead", StringUtils.trimToEmpty(otherInfo.getImageHead()));
				//otherCredit.put("creditNum", userInfoService.getCredit(otherInfo));
				otherCredit.put("creditNum", otherInfo.getReputation());
				otherCredit.put("selfNum", otherInfo.getSelfNum());
				otherCredit.put("idcardNum", otherInfo.getIdcardNum() == 100 ? 100 : 33);
				otherCredit.put("taskNum", otherInfo.getTaskNum()>0?otherInfo.getTaskNum()/10:0);
				otherCredit.put("updateTime", DateTimeUtils.formatDateTime2String(otherInfo.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
				infoMap.put("otherCredit", otherCredit);
			}
			//UserInfo userInfo = userInfoService.selectByUserId(userId);
			UserInfo userInfo = userInfoService.selectByPrimaryKey(userId);
			myCredit.put("nickName", PeiniUtils.updateNickName(userInfo.getNickname(),userInfo.getAccCode()));
			myCredit.put("imgHead", StringUtils.trimToEmpty(userInfo.getImageHead()));
			//myCredit.put("creditNum", userInfoService.getCredit(userInfo));
			myCredit.put("creditNum", userInfo.getReputation());
			myCredit.put("selfNum", userInfo.getSelfNum());
			myCredit.put("idcardNum", userInfo.getIdcardNum() == 100 ? 100 : 33);
			myCredit.put("taskNum", userInfo.getTaskNum()>0?userInfo.getTaskNum()/10:0);
			myCredit.put("updateTime", DateTimeUtils.formatDateTime2String(userInfo.getUpdateTime(), "yyyy-MM-dd HH:mm:ss"));
			infoMap.put("myCredit", myCredit);
	    } catch (Exception e) {
	    	infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败"); 
	    	logger.error(e.getMessage(),e);
	    }
		return infoMap;
	}
	
	/**
	 * 排行榜
	 * @param dType 0 总排行榜 1 月排行榜,2上月排行
	 * @param rType 1 金币榜 2 土豪榜 3 诚信榜,userId 用户id
	 * @return
	 */
	@RequestMapping(value="/getRank")
	@ResponseBody
	public Object getRank(HttpServletRequest request,int dType,int rType,String userId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("resultCode", Constants.SUCCESS);
		infoMap.put("resultDesc", "成功");
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			String reqUserId = obj.getString("userId");
			
			UserInfo userInfo = userInfoMapper.selectByPrimaryKey(reqUserId);
			if(!PeiniUtils.isAddUserInfo(userInfo)){
				infoMap.put("resultCode", Constants.INFO_INVALIDATE);
				infoMap.put("resultDesc", "必要资料不全，请完善资料");
				return infoMap;
			}
			
			//排行榜数据更新提示语，逻辑控制resultCode=400时不展示数据
			SysConfig config = sysConfigMapper.selectByPrimaryKey(8);
			if(config!=null){
				Date rankTime = DateTimeUtils.formatString2Date(config.getConval(), "yyyyMMdd");
				if(rankTime.after(new Date())){//未到设定日期
					infoMap.put("resultCode", 400);
					return infoMap;
				}
			}
			
			List<LinkedHashMap<String,Object>> rankList = userInfoService.getRank(dType, rType);
			for (LinkedHashMap<String, Object> map : rankList) {
				if (map.get("nickname")!=null&&map.get("accCode")!=null) {
					map.put("nickname",PeiniUtils.updateNickName(map.get("nickname").toString(),map.get("accCode").toString()));
				}
				if(map.get("userId").toString().equals(reqUserId)){
					map.put("userId", userId);
				}
			}
			infoMap.put("rankList", rankList);
			
			HashMap<String,Object> myRank = userInfoService.getUserRank(dType, rType, reqUserId);
			/*if (myRank.get("nickname")!=null&&myRank.get("accCode")!=null) {
				myRank.put("nickname",PeiniUtils.updateNickName(myRank.get("nickname").toString(),myRank.get("accCode").toString()));
			}*/
			
			UserInfo uInfo = userInfoMapper.selectByPrimaryKey(reqUserId);
			myRank.put("accCode", uInfo.getAccCode());
			myRank.put("nickname", PeiniUtils.updateNickName(uInfo.getNickname(), uInfo.getAccCode()));
			myRank.put("imageHead", StringUtils.trimToEmpty(uInfo.getImageHead()));
			myRank.put("age", uInfo.getAge());
			myRank.put("sex", uInfo.getSex());
			
			myRank.put("industry", (uInfo.getIndustry() == null || uInfo.getIndustry()==0) ? "" : PeiniUtils.industryMap.get(uInfo.getIndustry()).getCodesName());
			
			myRank.put("userId", userId);
			infoMap.put("myRank", myRank);
			
	    } catch (Exception e) {
	    	infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败"); 
	    	logger.error(e.getMessage(),e);
	    }
		//logger.info(net.sf.json.JSONObject.fromObject(infoMap));
		return infoMap;
	}
	
	/**
	 * 
	 * @param req
	 * @param resp
	 * @param dType   
	 * @param rType1       人气榜
	 * @param userId   用户id 
	 */
	@ApiOperation("人气榜")
	@RequestMapping(value="/fansRank",method=RequestMethod.GET)
	@ResponseBody
	public Object getRank(HttpServletRequest req,HttpServletResponse resp,String userId,String ver){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		infoMap.put("fansRank", userConcernService.getRank(1,10));
		LinkedHashMap<String, Object> userConcern= userConcernService.getRankByUserId(userId);
		infoMap.put("myRank",userConcern);
		//当前用户粉丝排行中的位置
	/*	infoMap.put("position",userConcernService.getRankPosition(userId))*/;
		return ResultMessage.SUCCESS.setData(infoMap);
	}

	
	/**
	 * 开关排行榜
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/updateSwitchRank")
	@ResponseBody
	public Object updateSwitchRank(HttpServletRequest request,
			@RequestParam(value="userId") String userId,
			@RequestParam(value="isRank") Integer isRank
			){
		
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			UserInfo userInfo = new UserInfo();
			userInfo.setId(userId);
			userInfo.setIsRank(isRank);
			
			int updateNum=userInfoService.updateSwitchRank(userInfo);
			if (updateNum>0){
				infoMap.put("resultCode", Constants.SUCCESS);
				infoMap.put("resultDesc", "成功");
			}
	    } catch (Exception e) {
	    	infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败"); 
	    	logger.error(e.getMessage(),e);
	    }
		return infoMap;
	}
	
	/**
	 * 设置中显示排行版状态
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/getSwitchRank")
	@ResponseBody
	public Object getSwitchRank(HttpServletRequest request,String userId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			int userInfo=userInfoService.getSwitchRank(userId);
			//logger.info(userInfo+"这是参数");
			infoMap.put("isRank",userInfo);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败"); 
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 财富积分查询
	 * @param userId 用户id
	 * @return
	 */
	@RequestMapping(value="/getUserGoldAndScore")
	@ResponseBody
	public Object getUserGoldAndScore(HttpServletRequest request,String userId){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			LinkedHashMap<String, Object> userMap = new LinkedHashMap<String, Object>();
			UserInfo userInfo = userInfoService.selectByUserId(userId);
			userMap.put("imageHead", StringUtils.isNotBlank(userInfo.getImageHead())?userInfo.getImageHead():"");
			UserAccount userAccount = userAccountService.selectByUserId(userId);
			//userMap.put("gold", CommonUtils.doubleTrans((double)userAccount.getGold()/100));
			BigDecimal gold = new BigDecimal(userAccount.getGold()).divide(new BigDecimal("100"));
			userMap.put("gold", gold.toString());
			userMap.put("score", userAccount.getScore());
			infoMap.put("userInfo",userMap);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.FAIL);
			infoMap.put("resultDesc", "网络请求失败"); 
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 获取空间系统背景图片
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/getSysBagImages")
	@ResponseBody
	public Object getSysBagImages(HttpServletRequest request){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			ResourceBundle resource = ResourceBundle.getBundle("config");
			String key = resource.getString("sysBgImgSrces"); 
			
			StringBuffer sbf = new StringBuffer("");
			String [] ss = key.split(";");
			for (int i = 0; i < ss.length; i++) {
				if(StringUtils.isNotBlank(ss[i])){
					sbf.append("/upload/sysBgImgs/"+ss[i]+",");
				}
			}
			
			infoMap.put("imgs", sbf.toString());
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败"); 
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	@RequestMapping(value="/getEmUserHeadAndNickname")
	@ResponseBody
	public Object getEmUserHeadAndNickname(HttpServletRequest request,
			@RequestParam(value="nameStr",required=false) String nameStr
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			if(StringUtils.isBlank(nameStr)){
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "参数不能为空");
				return infoMap;
			}
			
			int n = -1;
			String [] ss = nameStr.split(",");
			List<String> nameList = new ArrayList<String>();
			List<HashMap<String, Object>> maps = new ArrayList<HashMap<String,Object>>();
			
			for (int i = 0; i < ss.length; i++) {
				nameList.clear();
				if(StringUtils.isNotBlank(ss[i])){
					nameList.add(ss[i]);
					List<UserInfo> list = userInfoMapper.getUserInfoByMobiles(nameList);
					if(list.size() > 0){
						for (UserInfo user : list) {
							HashMap<String, Object> map = new HashMap<String, Object>();
							map.put("sex", user.getSex() == null ? "" : user.getSex().toString());
							map.put("headImg", StringUtils.trimToEmpty(user.getImageHead()));
							map.put("nickName", StringUtils.trimToEmpty(PeiniUtils.updateNickName(user.getNickname(),user.getAccCode())));
							map.put("userPhone", ss[i]);
							maps.add(map);
						}
					}else{
						HashMap<String, Object> map = new HashMap<String, Object>();
						map.put("userPhone", ss[i]);
						map.put("sex", "");
						map.put("headImg", "");
						if(ss[i].equals("admin")){
							map.put("nickName", "系统管理员");
						}else{
							map.put("nickName", ss[i]);
						}
						maps.add(map);
					}
				}
			}
			
			/*List<String> nameList = Arrays.asList(ss);
			for (int i = 0; i < nameList.size(); i++) {
				if(nameList.get(i).equals("admin")){
					n = i;
				}
			}
			
			List<HashMap<String, Object>> maps = new ArrayList<HashMap<String,Object>>();
			if(nameList.size()>0){
				if(n == -1){
					List<UserInfo> list = userInfoMapper.getUserInfoByMobiles(nameList);
					
					for (int i = 0; i < list.size(); i++) {
						UserInfo user = list.get(i);
						HashMap<String, Object> map = new HashMap<String, Object>();
						map.put("sex", user.getSex() == null ? "" : user.getSex().toString());
						map.put("headImg", StringUtils.trimToEmpty(user.getImageHead()));
						map.put("nickName", StringUtils.trimToEmpty(user.getNickname()));
						maps.add(map);
					}
				}else if(nameList.size() == n+1){
					List<UserInfo> list = userInfoMapper.getUserInfoByMobiles(nameList);
					
					for (int i = 0; i < list.size(); i++) {
						UserInfo user = list.get(i);
						HashMap<String, Object> map = new HashMap<String, Object>();
						map.put("sex", user.getSex() == null ? "" : user.getSex().toString());
						map.put("headImg", StringUtils.trimToEmpty(user.getImageHead()));
						map.put("nickName", StringUtils.trimToEmpty(user.getNickname()));
						maps.add(map);
					}
					HashMap<String, Object> map = new HashMap<String, Object>();
					map.put("sex", "");
					map.put("headImg", "");
					map.put("nickName", "系统管理员");
					maps.add(map);
				}else{
					List<UserInfo> list = userInfoMapper.getUserInfoByMobiles(nameList);
					
					for (int i = 0; i < list.size(); i++) {
						if(i == n){
							HashMap<String, Object> map = new HashMap<String, Object>();
							map.put("sex", "");
							map.put("headImg", "");
							map.put("nickName", "系统管理员");
							maps.add(map);
						}
						UserInfo user = list.get(i);
						HashMap<String, Object> map = new HashMap<String, Object>();
						map.put("sex", user.getSex() == null ? "" : user.getSex().toString());
						map.put("headImg", StringUtils.trimToEmpty(user.getImageHead()));
						map.put("nickName", StringUtils.trimToEmpty(user.getNickname()));
						maps.add(map);
					}
				}
			}*/
			
			infoMap.put("data", maps);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败"); 
			logger.error(e.getMessage(),e);
		}
		return infoMap;
	}
	
	/**
	 * 金币转账用户信息确认
	 * @author Han Guohong
	 * @param request
	 * @param userId
	 * @param otherId
	 * @return
	 */
	@RequestMapping(value="/payGoldSureUserInfo")
	@ResponseBody
	public Object payGoldSureUserInfo(HttpServletRequest request,
			@RequestParam(value="userId") String userId,
			@RequestParam(value="other",required=false) String other,//手机号或者用户账号
			@RequestParam(value="otherId",required=false) String otherId,//用户id
			@RequestParam(value="taskId",required=false) Long taskId
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			if(taskId == null){
				if(StringUtils.isBlank(other) && StringUtils.isBlank(otherId)){
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "缺少参数");
					return infoMap;
				}
			}
			
			UserInfo otherInfo = new UserInfo();
			if(taskId != null && taskId != 0){
				TaskInfo taskInfo = taskInfoMapper.selectByPrimaryKey(taskId.intValue());
				if(taskInfo.getUserId().equals(userId)){
					otherInfo = userInfoMapper.selectByPrimaryKey(taskInfo.getOtherUserId());
					if(otherInfo == null){
						infoMap.put("resultCode", Constants.FAIL);
						infoMap.put("resultDesc", "没有查到相关用户信息");
						return infoMap;
					}
				}else{
					otherInfo = userInfoMapper.selectByPrimaryKey(taskInfo.getUserId());
					if(otherInfo == null){
						infoMap.put("resultCode", Constants.FAIL);
						infoMap.put("resultDesc", "没有查到相关用户信息");
						return infoMap;
					}
				}
			}else if(StringUtils.isNotBlank(other)){
				UserInfoExample example = new UserInfoExample();
				example.or().andUserPhoneEqualTo(other);
				example.or().andAccCodeEqualTo(other);
				List<UserInfo> userList = userInfoMapper.selectByExampleWithBLOBs(example);
				if(userList.size()> 0){
					otherInfo = userList.get(0);
					otherId = otherInfo.getId();
				}else{
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "没有查到相关用户信息");
					return infoMap;
				}
			}else{
				otherInfo = userInfoMapper.selectByPrimaryKey(otherId);
				if(otherInfo == null){
					infoMap.put("resultCode", Constants.FAIL);
					infoMap.put("resultDesc", "没有查到相关用户信息");
					return infoMap;
				}
			}
			
			/*UserAccountExample example = new UserAccountExample();
			com.jsz.peini.bean.user.UserAccountExample.Criteria criteria = example.createCriteria();
			criteria.andUserIdEqualTo(userId);
			List<UserAccount> accounts = userAccountMapper.selectByExample(example);
			
			UserAccount userAccount = accounts.get(0);
			if(StringUtils.isBlank(userAccount.getPayPassword())){
				infoMap.put("resultCode", Constants.NOPAYPASS);
				infoMap.put("resultDesc", "您还没有设置支付密码");
				return infoMap;
			}*/
			
			HashMap<String, String> userInfo = new HashMap<String, String>();
			userInfo.put("userId", otherInfo.getId());
			userInfo.put("headImg", StringUtils.trimToEmpty(otherInfo.getImageHead()));
			userInfo.put("sex", otherInfo.getSex() == null ? "" : otherInfo.getSex().toString());
			userInfo.put("age", otherInfo.getAge() == null ? "" : otherInfo.getAge().toString());
			if(otherInfo.getNowProvince() == null || otherInfo.getNowProvince() == 0){
				userInfo.put("provinceName", "");
			}else{
				userInfo.put("provinceName", PeiniUtils.cityMap.get(otherInfo.getNowProvince().toString()).getCodesName());
			}
			if(otherInfo.getNowCity() == null || otherInfo.getNowCity() == 0){
				userInfo.put("cityName", "");
			}else{
				userInfo.put("cityName", PeiniUtils.cityMap.get(otherInfo.getNowCity().toString()).getCodesName());
			}
			
			userInfo.put("ID", otherInfo.getAccCode());
			userInfo.put("userPhone", otherInfo.getUserPhone());
			userInfo.put("nickName",PeiniUtils.updateNickName(otherInfo.getNickname(),otherInfo.getAccCode()) );
			userInfo.put("spaceBgImg", StringUtils.trimToEmpty(otherInfo.getSpaceBgImg()));
			
			boolean flag1 = false;//我关注了他
			boolean flag2 = false;//他关注了我
			UserConcernExample example1 = new UserConcernExample();
			example1.or().andUserIdEqualTo(userId);
			example1.or().andOtherIdEqualTo(userId);
			List<UserConcern> list = userConcernMapper.selectByExample(example1);
			for (UserConcern userConcern : list) {
				if(userConcern.getUserId().equals(userId)){//我关注的人
					if(userConcern.getOtherId().equals(otherId)){
						flag1 = true;
					}
				}else{//我的粉丝
					if(userConcern.getUserId().equals(otherId)){
						flag2 = true;
					}
				}
			}
			if(flag1 == false && flag2 == false){
				userInfo.put("relation", "陌生人");//陌生人
			}else if(flag1 == true && flag2 == true){
				userInfo.put("relation", "双方关注");
			}else if(flag1 == true && flag2 == false){
				userInfo.put("relation", "关注");
			}else if(flag1 == false && flag2 == true){
				userInfo.put("relation", "粉丝");
			}
			
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
			infoMap.put("data", userInfo);
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
		
	}
	
	/**
	 * 拉黑接口
	 * @author Han Guohong
	 * @param request
	 * @param userId
	 * @param otherId
	 * @return
	 */
	@RequestMapping(value="/doUserBlack")
	@ResponseBody
	public Object doBlack(HttpServletRequest request,
			@RequestParam(value="userId") String userId,
			@RequestParam(value="otherId") String otherId
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			if(StringUtils.isBlank(otherId)){
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "缺少参数");
				return infoMap;
			}
			
			UserInfo userInfo = new UserInfo();
			userInfo = userInfoMapper.selectByPrimaryKey(userId);
			if(userInfo == null){
				infoMap.put("resultCode", Constants.FAIL);
				infoMap.put("resultDesc", "没有查到相关用户信息");
				return infoMap;
			}
			
			userInfo.setBlackList(StringUtils.trimToEmpty(userInfo.getBlackList()+otherId+","));
			userInfoMapper.updateByPrimaryKeyWithBLOBs(userInfo);
			
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
		
	}
	
	/**
	 * 根据注册时间段获取用户信息(给活动公司)
	 * @author Han Guohong
	 * @param request
	 * @param start
	 * @param end
	 * @return
	 */
	@RequestMapping(value="/user_ac_getByBTtime")
	@ResponseBody
	public Object user_ac_getByBTtime(HttpServletRequest request,
			@RequestParam(value="start") String start,
			@RequestParam(value="end") String end
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			Date startTime = DateTimeUtils.formatString2Date(start, "yyyy-MM-dd HH:mm:ss");
			Date endTime = DateTimeUtils.formatString2Date(end, "yyyy-MM-dd HH:mm:ss");
			
			List<String> tels = new ArrayList<String>();
			
			String str = "";
			
			UserInfoExample example = new UserInfoExample();
			example.createCriteria().andRegTimeBetween(startTime, endTime);
			List<UserInfo> list = userInfoMapper.selectByExample(example);
			logger.info("" + list.size());
			for (UserInfo userInfo : list) {
				String tel = userInfo.getUserPhone();
				String phone = tel.substring(0, 3);
				phone += "****";
				phone += tel.substring(7, tel.length());
				tels.add(phone);
				
				str += phone+",";
			}
			/*tels.add("13912345678");
			tels.add("13912345679");
			tels.add("13912345670");*/
			logger.info(str);
			
			infoMap.put("data", tels);
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
		
	}
	
	/**
	 * 判断用户信息完善状态
	 * @author Han Guohong
	 * @param request
	 * @param userId
	 * @return
	 */
	@RequestMapping(value="/userIsHead")
	@ResponseBody
	public Object userIsHead(HttpServletRequest request,
			@RequestParam(value="userId") String userId
			){
		LinkedHashMap<String, Object> infoMap = new LinkedHashMap<String, Object>();
		try {
			
			JSONObject obj = PeiniUtils.validToken(userId);
			if(obj.getInteger("resultCode") != 1){
				return obj;
			}
			userId = obj.getString("userId");
			
			UserInfo uInfo = userInfoMapper.selectByPrimaryKey(userId);
			
			if(!PeiniUtils.isAddUserInfo(uInfo)){
				infoMap.put("resultCode", Constants.INFO_INVALIDATE);
				infoMap.put("resultDesc", "必要资料不全，请完善资料");
				return infoMap;
			}
			
			if(uInfo.getImgheadIsdelete() == null){
				uInfo.setImgheadIsdelete(0);
			}
			if (uInfo.getImgheadIsdelete()==1) {
				infoMap.put("isHead", 1);
			}else if (uInfo.getImgheadIsdelete()==0) {
				infoMap.put("isHead", 0);
			}
			
			infoMap.put("resultCode", Constants.SUCCESS);
			infoMap.put("resultDesc", "成功");
		} catch (Exception e) {
			infoMap.put("resultCode", Constants.EXCEPTION);
			infoMap.put("resultDesc", "网络请求失败");
			logger.error(e.getMessage(),e);
		}
		return infoMap;
		
	}
	
	
//	@ApiOperation("获取用户列表")
//	@RequestMapping(value = "/user/list", method=RequestMethod.GET)
//	@ResponseBody
//	public Object getPartyList(
//			@ApiParam(required=true, value="是否是官方聚会")  @RequestParam("offical") Boolean offical,
//			@ApiParam(required=true)  @RequestParam("pageSize") Integer pageSize,
//			@ApiParam(required=true)  @RequestParam("pageNum") Integer pageNum
//			) {
//		List<PartyInfo> partyInfoList = partyService.getPartyInfoList(offical,pageSize,pageNum);
//		return ResultMessage.SUCCESS.setData(partyInfoList);
//	}
}
